<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.List" %>
<%@page import="com.sql.Sql" %>
<html>
    <head>
        <meta http-equiv="Content-Type"
              content="text/html; charset=UTF-8">
        <title>Struts - Musica</title>
        <style type="text/css">
            @import "/musica/musica.css";
        </style>
    </head>
    <body>
        <%
        List list = Sql.consulta(
                "SELECT idTema,titulo,tema,duracion " +
                "FROM cds INNER JOIN temas " +
                "ON cds.idCd=temas.idCd");

        if (list == null) {%>
        <p class="titulo">No hay acceso a base de datos</p>
        <%} else {%>
        <p class="titulo">Lista de Temas</p>
        <div class="center">
            <table border="4" width="90%">
                <%
            for (int fil = 0; fil < list.size(); ++fil) {
                out.println("<tr bgcolor=" +
                        ((fil % 2) == 1
                        ? "LightGreen" : "Cyan") + ">");

                Object[] fila = (Object[]) list.get(fil);

                for (int col = 1; col < fila.length; ++col) {
                    if (fil == 0) {    // titulos
                        out.println("<th class'color'>" + fila[col] + "</th>");
                        if (col == (fila.length - 1)) {
                            out.println("<th class'color' style='text-align:center'>acci&oacute;n</th>");
                        }
                    } else {    // data
                        out.println("<td>" + (fila[col].toString().length() != 0
                                ? fila[col] : "&nbsp;") + "</td>");
                        if (col == (fila.length - 1)) {	// en fila[0] está el ID
                            out.println("<td style='text-align:center'>" +
                                    "<a href='/musica/jsp/temaUpd.jsp?idTema=" + fila[0] +
                                    "'><img src='/musica/images/upd.gif' border=0 title='Editar'></a>");
                            out.println("&nbsp;&nbsp;&nbsp;&nbsp;" +
                                    "<a href='/musica/jsp/temaDel.jsp?idTema=" + fila[0] +
                                    "'><img src='/musica/images/del.gif' border=0 title='Eliminar'>" +
                                    "</a></td>");
                        }
                    }
                }
                out.println("</tr>");
            }
                %>
            </table>
        </div>
        <%}%>
        <p class="center">
            <a href="/musica/portada.html">Home</a>
        </p>
    </body>
</html>

